import Layout from '../component/baseJs/Layout';
// import {concurrentRequests} from '../component/baseJs'

// 深拷贝
const cloneDeep = (data, hash = new WeakMap()) => {
  if (!data || typeof data !== 'object') return data;
  const type = Object.prototype.toString.call(data);
  if (hash.has(data)) {
    // 防止闭环
    return hash.get(data);
  }
  if (type === '[object object]') {
    const newDate = {};
    const objKeys = Object.keys(data);
    objKeys.forEach(v => {
      const defaultDataVal = data[v];
      if (!defaultDataVal || typeof defaultDataVal !== 'object') {
        newDate[v] = defaultDataVal;
      } else if (Array.isArray(defaultDataVal)) {
        newDate[v] = [...defaultDataVal];
      } else if (defaultDataVal instanceof Set) {
        newDate[v] = new Set([...defaultDataVal]);
      } else if (defaultDataVal instanceof Map) {
        newDate[v] = new Map([...defaultDataVal]);
      } else {
        hash.set(data, data);
        newDate[v] = cloneDeep[(defaultDataVal, hash)];
      }
    });
    return newDate;
  } else if (type === '[object Array]') {
    const newDate = [];
    const len = data.length;
    for (let i = 0; i < len; i++) {
      newDate.push(data[i]);
    }
    return newDate;
  } else if (type === '[object Date]') {
    return new Date(+data);
  }
  return data;
};

// 测试数据项
// var data = {
//   age: 18,
//   name: "liuruchao",
//   education: ["小学", "初中", "高中", "大学", undefined, null],
//   likesFood: new Set(["fish", "banana"]),
//   friends: [
//     { name: "summer",  sex: "woman"},
//     { name: "daWen",   sex: "woman"},
//     { name: "yang",    sex: "man" }  ],
//   work: {
//     time: "2019",
//     project: { name: "test",obtain: ["css", "html", "js"]}
//   },
//   play: function() {    console.log("玩滑板");  }
// }
// data = [
//   { name: "summer",  sex: "woman"},
//   { name: "daWen",   sex: "woman"},
//   { name: "yang",    sex: "man" }  ]

var data = {
  name: 'foo',
  child: null
};
data.child = data;
const newData = cloneDeep(data);
// newData.push(111)
console.log(data, newData);

// https://blog.csdn.net/Niucode/article/details/127575421
// 一、同步——>异步——>微任务——>宏任务。JS是单线程，碰见同步执行同步直到执行完毕，遇到异步放到执行队列中去，异步包括宏任务和微任务，在异步中微任务是优于宏任务执行的。
// 二、<script>整体代码可看作宏任务，还有就是如果宏任务里包括微任务，那就可以看作宏任务的执行顺序先于微任务。
setTimeout(() => {
  console.log('a');
}, 0);
const objEventLoop = {
  func: function () {
    setTimeout(function () {
      console.log('B');
    }, 0);
    return new Promise(function (res) {
      console.log('c');
      res();
    });
  }
};
objEventLoop.func().then(() => {
  console.log('D');
});
console.log('E');

export default function BaseJs() {
  // concurrentRequests()
  return (
    <div className='my__component__wrapper'>
      BaseJs
      <Layout />
    </div>
  );
}
